package com.mapeditor.graph 
{
	import com.mapeditor.toolbar.MenuShape;
	import com.mapeditor.toolbar.MenuShapeItemProperties;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author SE
	 */
	public class Container extends Sprite
	{
		private static var instance:Container;  
		private var menuS:MenuShape;
		private var menuShow:Boolean;
		
		public static function getInstance():Container
		{
			if (instance == null)  
			{
                instance = new Container();  				
			}
            return instance;  
		}
		
		function Container() 
		{
			
		}
		
		public function addMenu():void {
			menuShow = false;
			var sub_menu_ship:MenuShape = new MenuShape();
			sub_menu_ship.addItemMenu(this._createMenuShapeItem(32,32,"ship01","img/menu/Ship01.png"));
			sub_menu_ship.addItemMenu(this._createMenuShapeItem(32,32,"ship02","img/menu/Ship02.png"));
			sub_menu_ship.addItemMenu(this._createMenuShapeItem(32, 32, "ship03", "img/menu/Ship03.png"));
			sub_menu_ship.outPut();
			
			var sub_menu_tank:MenuShape = new MenuShape();			
			sub_menu_tank.addItemMenu(this._createMenuShapeItem(64,45,"tank01","img/tank1.png"));
			sub_menu_tank.addItemMenu(this._createMenuShapeItem(64,45,"tank02","img/tank2.png"));
			sub_menu_tank.addItemMenu(this._createMenuShapeItem(64,45,"tank03","img/tank3.png"));
			sub_menu_tank.outPut();
			
			var sub_menu_tower:MenuShape = new MenuShape();
			sub_menu_tower.addItemMenu(this._createMenuShapeItem(32,32,"tower01","img/menu/tower01.png"));
			sub_menu_tower.addItemMenu(this._createMenuShapeItem(32, 32, "tower02", "img/menu/tower02.png"));
			sub_menu_tower.outPut();
			
			var sub_menu_powerup:MenuShape = new MenuShape();
			sub_menu_powerup.addItemMenu(this._createMenuShapeItem(32,32,"powerup_life","img/menu/powerup_life.png"));
			sub_menu_powerup.addItemMenu(this._createMenuShapeItem(32,32,"powerup_shot","img/menu/powerup_shot.png"));
			sub_menu_powerup.outPut();
			
			var sub_menu_bridge:MenuShape = new MenuShape();
			sub_menu_bridge.addItemMenu(this._createMenuShapeItem(32,32,"bridge","img/menu/bridge.png"));
			sub_menu_bridge.addItemMenu(this._createMenuShapeItem(32,32,"bridge_rotate","img/menu/bridge_rotate.png"));
			sub_menu_bridge.outPut();
			
			/*var sub_menu_build:MenuShape = new MenuShape();
			sub_menu_build.addItemMenu(this._createMenuShapeItem(134,85,"house_ramp","img/menu/build/house_ramp.png"));
			sub_menu_build.addItemMenu(this._createMenuShapeItem(90,116,"house_corner","img/menu/build/house_corner.png"));
			sub_menu_build.outPut();
			*/
			
			menuS = new MenuShape();
			menuS.addItemMenu(this._createMenuShapeItem(32,32,"ship01","img/menu/Ship01.png",sub_menu_ship));
			menuS.addItemMenu(this._createMenuShapeItem(32,32,"tower01","img/menu/tower01.png",sub_menu_tower));
			menuS.addItemMenu(this._createMenuShapeItem(32,32,"powerup_life","img/menu/powerup_life.png",sub_menu_powerup));
			menuS.addItemMenu(this._createMenuShapeItem(32,32,"portal","img/menu/portal.png"));
			menuS.addItemMenu(this._createMenuShapeItem(32,32,"bridge","img/menu/bridge.png",sub_menu_bridge));
			menuS.addItemMenu(this._createMenuShapeItem(32,32,"terrain1","img/menu/terrain1.png"));
			menuS.addItemMenu(this._createMenuShapeItem(64, 45, "tank1", "img/tank1.png", sub_menu_tank));
			menuS.addItemMenu(this._createMenuShapeItem(64,45,"tower03","img/tower03.png"));
			//menuS.addItemMenu(this._createMenuShapeItem(32,32,"house_ramp","img/menu/terrain1.png",sub_menu_build));
			
			menuS.x = 200;
			menuS.y = 200;
			
			menuS.outPut();
			menuS.show();
			
			
			stage.doubleClickEnabled = true;
			stage.addEventListener(MouseEvent.DOUBLE_CLICK, rClick);
		}
		private function rClick(e:MouseEvent):void {
			if (!menuShow)
			{
				menuS.x = mouseX;
				menuS.y = mouseY;
			
				addChild(menuS);
			}
			else
				removeChild(menuS);
			
			menuShow = !menuShow;
				
		}
		
		private function _createMenuShapeItem(w:Number,h:Number,nm:String,path:String,subMenu:MenuShape=null):MenuShapeItemProperties {
			var prop:MenuShapeItemProperties = new MenuShapeItemProperties();
			prop.w = w;
			prop.h = h;
			prop.btnPath = path;
			prop.nm = nm;
			if (subMenu != null)
				prop.subMenu = subMenu;
			
			return prop;
		}
	}

}